/**
 * 自动查询构建器类型定义
 * @author sun
 * @date 2024-03-30
 */

/**
 * 查询操作符枚举
 */
export enum QueryOperator {
  EQUAL = '=',
  NOT_EQUAL = '!=',
  GREATER_THAN = '>',
  GREATER_THAN_OR_EQUAL = '>=',
  LESS_THAN = '<',
  LESS_THAN_OR_EQUAL = '<=',
  LIKE = 'like',
  IN = 'in',
  NOT_IN = 'not-in',
  BETWEEN = 'between',
  AND = 'and',
  OR = 'or',
}

/**
 * 条件装饰器类型
 */
export enum DecoratorType {
  CONDITION = 'condition',
  AND_GROUP = 'and_group',
  OR_GROUP = 'or_group',
  RANGE = 'range',
}

/**
 * 查询条件接口
 */
export interface IQueryCondition {
  operator: QueryOperator;
  field: string;
  value: any;
}

/**
 * 基础条件定义接口
 */
export interface IConditionDef {
  type: DecoratorType;
  operator: QueryOperator;
  field: string;
  defaultValue?: any;
}

/**
 * 范围条件定义接口
 */
export interface IRangeDef extends IConditionDef {
  type: DecoratorType.RANGE;
  minOperator: QueryOperator;
  maxOperator: QueryOperator;
}

/**
 * 条件组定义接口
 */
export interface IGroupDef extends IConditionDef {
  type: DecoratorType.AND_GROUP | DecoratorType.OR_GROUP;
}

/**
 * 查询条件构建结果类型
 */
export type QueryResult = any[] | undefined;

/**
 * 条件选项参数类型
 */
export interface ConditionOptions {
  skipEmpty?: boolean; // 是否跳过空值
  defaultValue?: any; // 默认值
}

/**
 * 元数据存储接口
 */
export interface MetadataStore {
  queryConditions?: Record<string | symbol, IConditionDef | IRangeDef | IGroupDef>;
  [key: string]: any;
}
